package com.itheima.service;

import com.itheima.dao.TeacherDao;
import com.itheima.domain.Teacher;

import java.util.ArrayList;

/*
老师业务处理类
增
删
改
查

1.业务判断
2.com.itheima.controller 和dao

 */
public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    //增
    public void addTeacher(Teacher teacher) {
        teacherDao.addTeacher(teacher);
    }

    //删
    public void deleteTeacher(String sid) {
        teacherDao.deleteTeacher(sid);
    }

    //改
    public void updateTeacher(String sid, Teacher newTea) {
        teacherDao.updateTeacher(sid, newTea);
    }


    //查

    public ArrayList<Teacher> findAllTeachers() {
        return teacherDao.findAllTeachers();
    }

    //判断工号是否存在
    public boolean isExist(String sid) {
        ArrayList<Teacher> list = teacherDao.findAllTeachers();
        for (int i = 0; i < list.size(); i++) {
            Teacher teacher = list.get(i);
            if (teacher.getSid().equals(sid)) {
                return true;
            }
        }
        return false;
    }

}
